import axios from 'axios';

export const isNewVersion = () => {
  const timestamp = new Date().getTime();
  const url = `//${window.location.host}/static/version.json?t=${timestamp}`;
  axios.get(url).then(res => {
    if (res.status === 200) {
      const currVersion = res.data.version;
      const localVersion = localStorage.getItem('CRM_VERSION');
      // 没有版本号或版本号不存在时，自动刷新页面
      if (!localVersion || (localVersion && localVersion !== currVersion)) {
        localStorage.setItem('CRM_VERSION', currVersion);
        window.location.reload();
      }
    }
  });
};
